﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "OwnerPtr.h"

// std headers
#include <memory>

#include <QStringList>
// custom headers
#include "GmepGcsMainUI.h"

#include "IFamilyFile.h"

namespace gmepgcs
{
    class SelectingFileItem;
}

namespace gmep
{
    class IGmepCategoryInfo;
}

namespace pugi
{
    class xml_document;
}

struct GmepComponentType;
struct GmepComponent;

namespace gmepgcs 
{
    class GCS_MAINUI_EXPORTS UploadWindow
    {

    private:
        UploadWindow();
        UploadWindow(const UploadWindow &) = default;
        UploadWindow &operator=(const UploadWindow &) = default;
        virtual ~UploadWindow();

    public:
        static UploadWindow *Get();

    public:

        bool AddTaskLocal(const std::wstring &projectId, const QStringList pathList, bool bIsConnect, std::wstring* strError = nullptr);
        int CheckFileIsExistOnLocal(const std::wstring &projectId, QStringList& pathList);

        
    public:
        std::wstring CreateFamilyThumbnail(const std::wstring& gacFile) const;
        
        //************************************
        // Method:    CheckFileIsExist
        // FullName:  gcs::UploadWindow::CheckFileIsExist
        // Access:    private 
        // Returns:   bool 是否存在重名
        // Qualifier:
        // Parameter: const std::wstring & projectId 项目id
        // Parameter: const std::vector<gcmp::OwnerPtr<SelectingFileItem>> & vecSelectedFile 选择的文件
        // Parameter: std::vector<std::wstring> & strFileNameArr 名称已经存在的文件
        //************************************
       // bool CheckFileIsExist(const std::wstring &projectId, const std::vector<gcmp::OwnerPtr<SelectingFileItem>>& vecSelectedFile,std::vector<std::wstring>& strFileNameArr);
        bool AddSelectedFile(const std::wstring &projectId, const std::vector<gcmp::OwnerPtr<SelectingFileItem>>& vecSelectedFile, bool bIsConnect,std::wstring* strError = nullptr) const;
        bool CopySingleFile(const std::wstring& srcFilePath, const std::wstring& targetFilePath) const;
        bool GetComponentType(const std::wstring& gacFile, const gmep::IGmepCategoryInfo* pCategory, GmepComponent& comp) const;
        bool GetPropertyInfo(const gmep::IGmepCategoryInfo* pCategory, const std::map<std::wstring, std::tuple<std::wstring, std::wstring>>& mapProperty, 
            GmepComponentType& componentType) const;

        std::wstring CreateGeometryParamDefinitionsJson(gcmp::IFamilyFile* pIFamilyFile, const std::wstring& sParametersXml, const gmep::IGmepCategoryInfo* pCategory, GmepComponent& comp) const;
        bool GetParameterInfo(pugi::xml_document* xmlDoc, const std::wstring& sName, std::wstring& sStandardType, std::wstring& sParameterType, std::wstring& sType, std::wstring& sFormula, std::map<std::wstring, std::wstring>& mapValue) const;
        std::wstring GetParameterDisplayType(const gcmp::UniIdentity& parameterTypeId) const;
        std::wstring GetUnitType(const gcmp::UniIdentity& unitTypeId) const;
        std::wstring GetValueType(gcmp::ParameterStorageType eParameterStorageType) const;
        std::wstring GetParameterStorageType(gcmp::ParameterStorageType storageType) const;
    private:
        bool RemoveStandardNodesFromXML(const std::wstring& gacFile, const std::wstring& sParametersXml) const;
    private:
        static UploadWindow *s_pInstance;
    };
}